package com.ruoyi.stock2.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stock2.domain.SearchFromEsModelike;
import com.ruoyi.stock2.service.ISearchFromEsModelikeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 从es中查询与模型相似股票的整理Controller
 * 
 * @author ruoyi
 * @date 2021-09-08
 */
@Controller
@RequestMapping("/stock2/modelike")
public class SearchFromEsModelikeController extends BaseController
{
    private String prefix = "stock2/modelike";

    @Autowired
    private ISearchFromEsModelikeService searchFromEsModelikeService;

    @RequiresPermissions("stock2:modelike:view")
    @GetMapping()
    public String modelike()
    {
        return prefix + "/modelike";
    }

    /**
     * 查询从es中查询与模型相似股票的整理列表
     */
    @RequiresPermissions("stock2:modelike:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SearchFromEsModelike searchFromEsModelike)
    {
        startPage();
        List<SearchFromEsModelike> list = searchFromEsModelikeService.selectSearchFromEsModelikeList(searchFromEsModelike);
        return getDataTable(list);
    }

    /**
     * 导出从es中查询与模型相似股票的整理列表
     */
    @RequiresPermissions("stock2:modelike:export")
    @Log(title = "从es中查询与模型相似股票的整理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SearchFromEsModelike searchFromEsModelike)
    {
        List<SearchFromEsModelike> list = searchFromEsModelikeService.selectSearchFromEsModelikeList(searchFromEsModelike);
        ExcelUtil<SearchFromEsModelike> util = new ExcelUtil<SearchFromEsModelike>(SearchFromEsModelike.class);
        return util.exportExcel(list, "modelike");
    }

    /**
     * 新增从es中查询与模型相似股票的整理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存从es中查询与模型相似股票的整理
     */
    @RequiresPermissions("stock2:modelike:add")
    @Log(title = "从es中查询与模型相似股票的整理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SearchFromEsModelike searchFromEsModelike)
    {
        return toAjax(searchFromEsModelikeService.insertSearchFromEsModelike(searchFromEsModelike));
    }

    /**
     * 修改从es中查询与模型相似股票的整理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SearchFromEsModelike searchFromEsModelike = searchFromEsModelikeService.selectSearchFromEsModelikeById(id);
        mmap.put("searchFromEsModelike", searchFromEsModelike);
        return prefix + "/edit";
    }

    /**
     * 修改保存从es中查询与模型相似股票的整理
     */
    @RequiresPermissions("stock2:modelike:edit")
    @Log(title = "从es中查询与模型相似股票的整理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SearchFromEsModelike searchFromEsModelike)
    {
        return toAjax(searchFromEsModelikeService.updateSearchFromEsModelike(searchFromEsModelike));
    }

    /**
     * 删除从es中查询与模型相似股票的整理
     */
    @RequiresPermissions("stock2:modelike:remove")
    @Log(title = "从es中查询与模型相似股票的整理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(searchFromEsModelikeService.deleteSearchFromEsModelikeByIds(ids));
    }
}
